<template>
    <div>
        <my-main/>
        <div class="aui-logon-con">
            <div class="b-line">
                <input type="text" v-model="username" placeholder="手机号/邮箱/用户名">
            </div>
            <div class="b-line">
                <input type="password" v-model="password" placeholder="密码">
            </div>
            <div class="b-line">
                <input type="password" placeholder="确认密码">
            </div>
            <div class="aui-login-l">
                <a href="#" @click="reg()">注册</a>
            </div>
            <div class="aui-login-wen">
                <div class="aui-login-wen-a"><router-link :to="{name:'login'}">去登录</router-link></div>
            </div>
        </div>
    </div>
</template>
<script>
import myMain from '@/components/myMain'
// import {mapState} from 'vuex'
export default {
    name:'reg',
    data(){
        return{
            username:'',
            password:''
        }
    },
    components: {
        myMain
    },
    
    methods: {
        reg(){
            if(this.username!=''&&this.password!=''){
                let data = {
                    username:this.username,
                    password:this.password
                }
                let flag = true
                let userList = localStorage.getItem('userList')
                let userL = JSON.parse(userList)
                
                if(userL!=null){
                    for(let i=0;i<userL.length;i++){
                        if(userL[i].username==data.username){
                            flag=false
                        }
                    }
                }else{
                    userL = []
                }
                if(flag){
                    userL.push(data)
                    userList = JSON.stringify(userL)
                    console.log(userList)
                    localStorage.setItem('userList',userList)
                    if(confirm('注册成功是否跳转到登录页')){
                        location.href = '/#/login'
                    }
                }else{
                    alert('用户名重复')
                }
                console.log(userList)
            }else{
                alert('请输入用户名或密码')
            }
            


        }
    }
}
</script>
<style scoped src="../../static/css/ui.css">

</style>

